<template>
		<view class="">
			<up-popup :show="popupShow" mode="bottom" :round="20">
				<view class="authon-popup">
					<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" class="avatar-auth">手机号一键授权</button>
				</view>
			</up-popup>
		</view>
</template>

<script setup>
	import {ref,defineProps,defineEmits} from 'vue'
	import {
		getLogin,
		getUserDraw
	} from '@/api/http.js'
	const props = defineProps({
		popupShow:{
			type:Boolean,
			default:false
		}
	})
	const emits = defineEmits(['authonClick'])
	
	// 手机号授权
	const userData = ref(uni.getStorageSync('userData'))
	const token = ref(uni.getStorageSync('token'))
	const getPhoneNumber = async (e) => {
		// #ifdef MP-WEIXIN
		uni.login({
			provider: 'weixin', //使用微信登录
			success: async (loginRes) => {
				getLogin({
					logincode: loginRes.code,
					iv: e.detail.iv,
					encryptedData: e.detail.encryptedData,
					// originalType: 1,
				}).then((res) => {
					if (res.code != 200) {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						return
					}
					let result = JSON.parse(res.data)
					userData.value = result
					token.value = result.token
					uni.setStorageSync('token', result.token)
					uni.setStorageSync('userData', result)
					uni.showToast({
						title: '授权成功',
						icon: 'none'
					})
					emits('authonClick',false)
					
				})
			}
		});
		// #endif
	}
	

</script>

<style lang="scss" scoped>
	.authon-popup{
		padding: 80rpx 30rpx 40rpx;
	}
	.avatar-auth {
		font-size: 28rpx;
		padding: 0 !important;
		border: none;
		color:#ffffff;
		background-color:#009A4D;
	
		&::after {
			border: none;
		}
	}

</style>